<template>
  <div class="list">
    <div class="header" style="display: flex;justify-content: space-between;">
      <el-breadcrumb>
        <el-breadcrumb-item :to="{path:'/'}">首页</el-breadcrumb-item>
        <el-breadcrumb-item >投诉列表页</el-breadcrumb-item>
      </el-breadcrumb>
      <el-button style="background-color: #1dd0b7;color: #fff;height: 32px;width: 120px;" @click="goComplaint">去投诉</el-button>
    </div>
    <div class="main">
      <el-table
        v-loading="loading"
        :data="dataList"
        :header-cell-style="{
          color:'#000',background:'#f6fdfd',height:'44px'
        }"
        :row-style="{height:'50px'}"
      >
        <el-table-column label="序号" type="index" width="244"></el-table-column>
        <el-table-column label="投诉名称" prop="title" width="530"></el-table-column>
        <el-table-column label="创建时间" prop="createTime">
          <template slot-scope="scope">
            {{ parseTime(scope.row.createTime,'{y}-{m}-{d}') }}
          </template>
        </el-table-column>
        <el-table-column label="处理状态" prop="status">
          <template slot-scope="scope">
            <span v-if="scope.row.status == 0" style="color: #ff8200;">正在处理中</span>
            <span v-else>处理完成</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" prop="index">
          <template slot-scope="scope">
            <el-button type="text" size="mini" style="color: #1dd0b7;" @click="handleRow(scope.row)">查看</el-button>
          </template>
        </el-table-column>
      </el-table>
      <Pagination
        v-show="total > 0"
        :limit.sync = "queryParams.pageSize"
        :page.sync = "queryParams.pageNum"
        :total="total"
        @pagination="getData"
      />
    </div>
    <el-dialog
      title="投诉"
      :visible.sync="showDialog"
      width="800px"
      append-to-body
    >
      <el-form ref="form" :model="complaintData" label-width="80px" :rules="rules">
        <el-form-item label="投诉标题" prop="title">
          <el-input v-model="complaintData.title" placeholder="请输入投诉标题"/>
        </el-form-item>
        <el-form-item label="投诉信息" prop="content">
          <editor v-model="complaintData.content" :min-height="192" :height="400"/>
        </el-form-item>
        <el-form-item label="联系人" prop="contact">
          <el-input v-model="complaintData.contact" placeholder="请输入联系人"/>
        </el-form-item>
        <el-form-item label="联系电话" prop="contactTel">
          <el-input v-model="complaintData.contactTel" placeholder="请输入联系电话"/>
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button type="primary" @click="submitComplaint">确定</el-button>
        <el-button @click="cancel">取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {listComplaint,addComplaint} from '@/api/bid/complaint'
import { mapGetters } from 'vuex'
import Editor from '@/components/MyEditor'

export default {
  name: "list",
  components:{
    Editor
  },
  data() {
    return {
     loading:true,
     dataList:[],
     queryParams:{
      pageNum:1,
      pageSize:20
     },
     total:0,

     complaintData:{
      status: '0',
     },
     showDialog:false,
     rules:{
      title: [{
        required: true,
        message: "投诉标题不能为空",
      }],
      content: [{
        required: true,
        message: "投诉信息不能为空",
      }],
      contact: [{
        required: true,
        message: "联系人不能为空",
      }],
      contactTel: [{
        required: true,
        message: "联系电话不能为空",
      }],
     }
    }
  },
  created() {
    this.getData()
  },
  methods: {
    getData(){
      this.queryParams.id=this.userId
      listComplaint(this.queryParams).then(res=>{
        this.dataList = res.rows
        this.total = res.total
        this.loading = false
      })
    },
    handleRow(row){
      this.$router.push('/complaint/detail?id=' + row.id)
    },
    goComplaint(){
      this.complaintData={
        status: '0',
      }
      this.showDialog=true
    },
    submitComplaint(){
      this.$refs['form'].validate(valid => {
        if (valid) {
          this.complaintData.enterpriseId = this.userId
          addComplaint(this.complaintData).then(response => {
            this.msgSuccess('新增成功')
            this.open = false
            this.getData()
            this.showDialog = false
          })
        }
      })
    },
    cancel(){
      this.showDialog=false
    },
  },
  computed:{
   ...mapGetters(['userId'])
  }
}
</script>

<style lang="scss" scoped>
::v-deep .el-pagination{
  display: flex;
  justify-content: center;
  position: relative;
}

::v-deep .el-pager .active{
  cursor: pointer;
  color: #1dd0b7;
}
</style>
